<?php
/**
 * Class to handle progressbars
 *
 * @author		Joachim Ruf, Loresoft Software (http://www.loresoft.de)
 * @license		New BSD License
 * @version		Class for Bootstrap v2.3.2
 *
 * */


Class Bootstrap_Progress_Handler
{
	private $bar = '';
	private $isSet = array(	'info'		=> false,
							'success'	=> false,
							'warning'	=> false,
							'danger'	=> false
						);

	/**
	 *
	 * */
	function __construct () {
	}


	/**
	 * Fuegt eine Info-Bar hinzu
	 * @param string $_text			: Anzeigetext in der Bar
	 * @param string $_percent		: Prozentuale einzunehmende Flaeche im Gesamtgefuege
	 * @return boolean
	 * */
	public function setBarInfo ($_text, $_percent) {
		if ($this->isSet['info'] === true) {
			return false;
		}
		if (!is_numeric($_percent)) {
			return false;
		}
		if (! ($_percent >=1 && $_percent <=100)) {
			return false;
		}

		$this->bar .= '<div class="bar" style="width: '.$_percent.'%">'.$_text.'</div>';
		return $this->isSet['info'] = true;
	}


	/**
	 * Fuegt eine Success-Bar hinzu
	 * @param string $_text			: Anzeigetext in der Bar
	 * @param string $_percent		: Prozentuale einzunehmende Flaeche im Gesamtgefuege
	 * @return boolean
	 * */
	public function setBarSuccess ($_text, $_percent) {
		if ($this->isSet['success'] === true) {
			return false;
		}
		if (!is_numeric($_percent)) {
			return false;
		}
		if (! ($_percent >=1 && $_percent <=100)) {
			return false;
		}

		$this->bar .= '<div class="bar bar-success" style="width: '.$_percent.'%">'.$_text.'</div>';
		return $this->isSet['success'] = true;
	}


	/**
	 * Fuegt eine Warning-Bar hinzu
	 * @param string $_text			: Anzeigetext in der Bar
	 * @param string $_percent		: Prozentuale einzunehmende Flaeche im Gesamtgefuege
	 * @return boolean
	 * */
	public function setBarWarning ($_text, $_percent) {
		if ($this->isSet['warning'] === true) {
			return false;
		}
		if (!is_numeric($_percent)) {
			return false;
		}
		if (! ($_percent >=1 && $_percent <=100)) {
			return false;
		}

		$this->bar .= '<div class="bar bar-warning" style="width: '.$_percent.'%">'.$_text.'</div>';
		return $this->isSet['warning'] = true;
	}


	/**
	 * Fuegt eine Danger-Bar hinzu
	 * @param string $_text			: Anzeigetext in der Bar
	 * @param string $_percent		: Prozentuale einzunehmende Flaeche im Gesamtgefuege
	 * @return boolean
	 * */
	public function setBarDanger ($_text, $_percent) {
		if ($this->isSet['danger'] === true) {
			return false;
		}
		if (!is_numeric($_percent)) {
			return false;
		}
		if (! ($_percent >=1 && $_percent <=100)) {
			return false;
		}

		$this->bar .= '<div class="bar bar-danger" style="width: '.$_percent.'%">'.$_text.'</div>';
		return $this->isSet['danger'] = true;
	}


	/**
	 * Gibt eine Progressbar aus
	 * @param bool $_useStrip	: Angabe, ob Striped verwendet werden soll
	 * @param bool $_useAnimation	: Angabe, ob die progress-stripe animiert werden soll
	 * @return string
	 * */
	public function display($_useStriped = false, $_useAnimation = false) {
		$arrClass	= array('progress');

		if ($_useStriped === true) {
			$arrClass[] = 'progress-striped';
		}
		if ($_useAnimation === true) {
			$arrClass[] = 'active';
		}

		return '<div class="'.implode(' ', $arrClass).'">
					'.$this->bar.'
				</div>';
	}


}


?>